package com.saascloud.openfeign.core;

import com.saascloud.Constants;
import com.saascloud.core.saas.SaasContextUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;


/**
 * @Author: liangxu
 * @Contact: one_dream@aliyun.com
 * @Date: 2022/5/30 15:55
 * @Version: 1.0
 * @Description:
 */
public class SaasFeignHeaderInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(Constants.HttpHeader.TOKEN, SaasContextUtil.getToken());
        requestTemplate.header(Constants.HttpHeader.TRACE_ID, SaasContextUtil.getTraceId());
        requestTemplate.header(Constants.HttpHeader.TENANT_ID, SaasContextUtil.getTenantId());
        /**
         * 如果value是json格式数据,使用如下格式调用，设计到中文需编码
         *         FeignUtils.createJsonHeader(requestTemplate, Constants.HttpHeader.USER,
         *         Base64.encode(JsonUtils.obj2String(SessionContextUtil.getUser())));
         */
    }
}
